/**
 * 
 */
package util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import modelo.Grafo;
import algoritmos.Kruskal;
import algoritmos.Prim;

/**
 * Classe para testes de c�digo
 * 
 * @author Rogerio
 * 
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Gerador gerador = new Gerador();
		int init = 1, end = 2;
		String textToFile = "";

		System.out.println("###################");
		System.out.println("Completos:");
		System.out.println("###################");
		textToFile += "\n###################";
		textToFile += "\nCompletos";
		textToFile += "\n###################";

		for (int i = init; i <= end; i++) {
			ArrayList<Grafo> grafos = gerador.geraGrafosCompletos(i * 100);
			System.out.println("Tamanho: " + i * 100);
			System.out.println();
			textToFile += "\nTamanho: " + i * 100 + "\n";
			textToFile += executaAlgoritmos(grafos);
		}

		System.out.println("###################");
		System.out.println("Nao Completos:");
		System.out.println("###################");
		textToFile += "\n###################";
		textToFile += "\nNao Completos";
		textToFile += "\n###################";

		for (int i = init; i <= end; i++) {
			ArrayList<Grafo> grafos2 = gerador.geraGrafosNaoCompletos(i * 100, i * 7);
			System.out.println("Tamanho: " + i * 100);
			System.out.println();
			textToFile += "\nTamanho: " + i * 100 + "\n";
			textToFile += executaAlgoritmos(grafos2);
		}
		// imprime no arquivo
		try {
			File file = new File("teste");
			BufferedWriter bw = new BufferedWriter(new FileWriter(file));
			bw.append(textToFile);
			bw.flush();
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String executaAlgoritmos(ArrayList<Grafo> grafos) {
		long currentTimeMillis, currentTimeMillis2;
		String textToFile = "";
		System.out.println("##### KRUSKAL #####");
		textToFile += "\n##### KRUSKAL #####";
		for (Grafo g : grafos) {
			currentTimeMillis = System.currentTimeMillis();
			Kruskal.kruskal(g);
			currentTimeMillis2 = System.currentTimeMillis();

			System.out.println(currentTimeMillis2 - currentTimeMillis);
			textToFile += "\nGRAFO: " + g.toString();
			textToFile += "\nTEMPO: " + (currentTimeMillis2 - currentTimeMillis) + ";";
		}

		System.out.println("##### PRIM #####");
		textToFile += "\n##### PRIM #####";
		for (Grafo g : grafos) {
			currentTimeMillis = System.currentTimeMillis();
			Prim.prim(g);
			currentTimeMillis2 = System.currentTimeMillis();

			System.out.println(currentTimeMillis2 - currentTimeMillis);
			textToFile += "\nGRAFO: " + g.toString();
			textToFile += "\nTEMPO: " + (currentTimeMillis2 - currentTimeMillis) + ";";
		}
		System.out.println();
		return textToFile;
	}

}
